package com.objectdraw.client.objectdraw;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Point;

/**
 * used to draw a yellow box around a selected object
 * 
 * @author jgulik, cfruehan
 *
 */
public class SelectionBox implements IDrawingObject{

	Color myColor;
	Point p1,p2;
	DrawingCanvas canvas;
	public boolean active;
	
	/**
	 * instantiate the selection box on the canvas in the parameter
	 * @param c the canvas upon which the selection box acts
	 */
	public SelectionBox(DrawingCanvas c){
		myColor=Color.yellow;
		canvas=c;
	}
	
	/**
	 * draw the selection box to the canvas
	 */
	public void drawMe(Graphics g) {
		if(active){
			//Color tempColor = g.getColor();
			g.setColor(myColor);
			g.drawRect(Math.min(p1.x,p2.x), Math.min(p1.y,p2.y), Math.abs(p1.x-p2.x), Math.abs(p1.y-p2.y));
			//g.setColor(tempColor);
		}
	}
	
	/**
	 * return height of bounding box
	 */
	public int getHeight() {
		return Math.abs(p1.y-p2.y);
	}

	/**
	 * return top of bounding box
	 */
	public int getTop() {
		return Math.min(p1.y,p2.y);
	}

	/**
	 * returns width of bounding box
	 */
	public int getWidth() {
		return Math.abs(p1.x-p2.x);
	}
	
	/**
	 * return the left side of the bounding box
	 */
	public int getLeft(){
		return Math.min(p1.x,p2.x);
	}

	/**
	 * always returns false
	 */
	public boolean isPointInObject(Point p) {
		return false;
	}
	
	/**
	 * unimplemented
	 */
	public void setmycolor(Color c){
	}

	/**
	 * move the anchor point by (+x, +y)
	 */
	public void moveAnchor(int x, int y) {
		p1.x+=x;
		p1.y+=y;
		p2.x+=x;
		p2.y+=y;
	}
}
